package org.goodsl.lesson.property.aop

import org.junit.Test

/**
 * Created with IntelliJ IDEA.
 * User: 萧猛
 * Date: 12-10-29
 * Time: 上午11:06
 * To change this template use File | Settings | File Templates.
 */
class TestAopDemo {
    @Test
    void Go() {


        def afterExed = false

        AopDemo.metaClass.propertyMissing = {String name ->
            println "in propertyMissing"
            Object obj = delegate
            return name

        }

        AopDemo.metaClass.beforePropertySet = {String name,Object newValue ->
            println "in beforePropertySet"


            if(name == "age" && newValue > 100){
                return false

            }
            return true

        }

        AopDemo.metaClass.afterPropertySet = {String name,Object newValue ->
            println "in afterPropertySet"
            afterExed = true

        }
        AopDemo d = new AopDemo()
        d.code = "100"
        assert d.Hello == "Hello"

        d.age = 50
        assert  d.age == 50
        d.age = 200
        assert  d.age == 50

        assert afterExed
    }

}